package cn.gok.server.controller;

import cn.gok.common.config.SystemLog;
import cn.gok.common.resp.Result;
import cn.gok.utils.ResultUtil;
import org.apache.shiro.SecurityUtils;
import org.apache.shiro.authc.AuthenticationException;
import org.apache.shiro.authc.UsernamePasswordToken;
import org.apache.shiro.subject.Subject;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author: DxlinY
 * @apiNote: 用户相关接口
 * @date: 2020/9/25
 * @time: 11:20
 */

@RestController
public class SysUserController {

    /**
     * 后台管理系统登录用
     *
     * @param username
     * @param password
     * @return
     */
    @RequestMapping(value = "/login", method = RequestMethod.POST)
    @SystemLog(model = "系统用户", method = "登录")
    public Result login(String username, String password) {
        UsernamePasswordToken usernamePasswordToken = new UsernamePasswordToken(username, password);
        Subject subject = SecurityUtils.getSubject();
        try {
            subject.login(usernamePasswordToken);
        } catch (AuthenticationException e) {
            return ResultUtil.loginFailed(null);
        }
        return ResultUtil.loginSuccess(null);
    }


}
